package com.mrobuy.jd.api;

import com.jd.open.api.sdk.JdClient;
import com.jd.open.api.sdk.domain.supplier.ProductManagementService.response.find.SimpleBrandDto;
import com.jd.open.api.sdk.request.supplier.VcItemBrandsFindRequest;
import com.jd.open.api.sdk.response.supplier.VcItemBrandsFindResponse;
import com.mrobuy.jdvc.entity.VCBrand;

import java.util.ArrayList;
import java.util.List;

/**
 *  获取类目下开通品牌信息
 *
 *  jingdong.vc.item.products.find
 *
 *  <url>https://open.jd.com/home/home#/doc/api?apiCateId=86&apiId=1681&apiName=jingdong.vc.item.products.find</url>
 *
 *
 *
 */
public class BrandFindClient extends JosClient<List<VCBrand>> {

    private VcItemBrandsFindRequest request=new VcItemBrandsFindRequest();

    public BrandFindClient(JdClient client) {
        super(client);
    }

    @Override
    public List<VCBrand> call() throws Exception {

        List<VCBrand> result = new ArrayList<>();


        VcItemBrandsFindResponse response= client.execute(request);

        if (response.getJosResultDto().getIsSuccess() ) {
            for (SimpleBrandDto simpleBrandDto : response.getJosResultDto().getResult()) {
                VCBrand vcBrand = new VCBrand();
                vcBrand.setBrandid(simpleBrandDto.getId());
                vcBrand.setName(simpleBrandDto.getName());
                result.add(vcBrand);
            }
        }

        return result;
    }
}
